package com.sh.personnel.service.impl;

import com.sh.personnel.domain.ITbDepartment;
import com.sh.personnel.mapper.IDeptMapper;
import com.sh.personnel.service.IDeptService;
import com.sh.personnel.util.TimeUtil;
import com.sh.personnel.util.TreeUtils;
import com.sh.personnel.vo.dto.SelectTreeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门管理业务
 * @author 林思浩
 * @date 2020/03/16 19:28
 */
@Service
public class IDeptServiceImpl implements IDeptService {

    @Autowired
    IDeptMapper deptMapper;

    @Override
    public List<SelectTreeDto> getDepartmentTree() {
        List<SelectTreeDto> departTree = deptMapper.findDepartmentTree();
        List<SelectTreeDto> deptTree = TreeUtils.generateSelectTree(departTree);
        return deptTree;
    }

    @Override
    public boolean addDepartment(ITbDepartment department) {
        department.setCreatetime(TimeUtil.currentMillis());
        int result = deptMapper.insertDepartment(department);
        return result>0 ? true : false;
    }

    @Override
    public ITbDepartment getDepartmentById(String id) {
        ITbDepartment department = deptMapper.findDepartmentById(id);
        return department;
    }

    @Override
    public boolean updateDepartment(ITbDepartment department) {
        department.setUpdatetime(TimeUtil.currentMillis());
        int result = deptMapper.updateDepartment(department);
        return result>0 ? true : false;
    }

    @Override
    public boolean deleteDepartmentById(String id) {
        int result = deptMapper.deleteDepartmentById(id);
        return result>0 ? true : false;
    }
}
